import { get, post } from "./request";
import { getURIParam } from "../utils/browser";
import { CAMPUS_DATA, DEVICENAME } from "../mock";
/**
 * 获取json配置
 * @param {*} mdId 
 * @returns 
 */
export async function getSceneConfig() {


  const data = await get(`./effectLight.json`, undefined) || {};
  return data;

}

/**
 * 获取场景中的树结构
 * @param {*} mdId 
 * @returns 
 */
export async function getInstanceTrees() {
  // const  data  = await get(`./data/environment.json`,undefined) || {};
  // return data;
  return new Promise((r) => {

  })
}


// 获取场景中的结构树
export async function  getThreeList() {
  const data =CAMPUS_DATA || {};
  return data.data || [];
}

// 获取场景中的结构树
export async function  getDeviceNameList(id) {
  const data = DEVICENAME || {};
  return data.tempData || [];
}

export function getTrankLine(id) {
  return []
}


export async function requestAPI(data) {
  return await requestByUrl(data)
}

//根据选择的3d接口发送请求
export function requestByUrl(obj) {
  if (obj.requestMethod === 'GET') {
    let params = KVToRecordable(obj.parameter)
    return get(obj.path, params)

  } else if (obj.requestMethod === 'POST') {
    let data = KVToRecordable(obj.parameter)
    return post(obj.path, data)
  }
}

function KVToRecordable(values) {
  const data = {}
  for (const item of values) {
    for (let keyi in item) {
      data[keyi] = item[keyi]
    }
  }
  return data
}